package p300;

public class Leetcode_326 {
    public static boolean isPowerOfThree(int n) {
        String a = Integer.toString(n, 3);
        System.out.println(a);
        int r = 0;
        for (char c : a.toCharArray()) {
            if (c != '1' && c != '0') {
                return false;
            } else if (c == '1') {
                r++;
                if (r > 1) {
                    return false;
                }
            }
        }
        return r != 0;
    }

    public static void main(String[] args) {
        System.out.println(isPowerOfThree(27));
        ;
    }
}
